package com.example.game.module;


import com.baomidou.mybatisplus.generator.FastAutoGenerator;
import com.baomidou.mybatisplus.generator.config.OutputFile;
import com.baomidou.mybatisplus.generator.engine.FreemarkerTemplateEngine;

import java.util.Collections;

public class GeneratorModule {
    public static void main(String[] args) {

        FastAutoGenerator.create("jdbc:mysql://localhost:3306/training",
                "root",
                "LJNYHHD")
                .globalConfig(builder -> {
                    builder.author("李杰")
                            .disableOpenDir()
                            .outputDir(System.getProperty("user.dir") + "/module/src/main/java");
                })
                //包配置
                .packageConfig(builder -> {
                    builder.parent("com.example.game.module")
                            .entity("entity")
                            .mapper("mapper")
                            .service("service")
                            .pathInfo(Collections.singletonMap(OutputFile.xml,
                                    System.getProperty("user.dir") + "/module/src/main/resources/mapper"));
                })
                //策略配置
                .strategyConfig(builder -> {
                    builder.addInclude("category")
                            //entity配置
                            .entityBuilder()
                            .enableLombok()
                            .enableChainModel()
                            .enableFileOverride()
                            .formatFileName("%s")
                            .javaTemplate("/templates/entity.java")
                            .disable()
                            .build()
                            //service配置
                            .serviceBuilder()
                            .formatServiceFileName("%sService")
                            .enableFileOverride()
                            .disableServiceImpl()
                            .serviceTemplate("/templates/service.java")
                            .build()
                            //mapper配置
                            .mapperBuilder()
                            .enableBaseResultMap()
                            .formatXmlFileName("%sMapper")
                            .formatMapperFileName("%sMapper")
                            .mapperTemplate("/templates/mapper.java")
                            .mapperXmlTemplate("/templates/mapper.xml")
                            .enableBaseResultMap() // 生成BaseResultMap
                            .enableFileOverride()
                            .disable()
                            .build()
                            .controllerBuilder()
                            .enableHyphenStyle() // 禁用Controller生成
                            .disable() // 明确禁用Controller生成
                            .build();

                })
                .templateEngine(new FreemarkerTemplateEngine())
                .execute();


    }
}
